package com.example.springboot.mapper;

import com.example.springboot.entity.Course;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CourseMapper {
    @Select("SELECT * FROM course")
    List<Course> findAll();    //

    //查询显示的总数  （下面分页）
    @Select("select count(*) from course where (course_grade=#{grade} or course_grade is null ) and course_class = #{choose}")
    Integer couraseTotal(Integer grade,String choose);

    // 查所有
    @Select("SELECT * FROM course limit #{pageNum}, #{pageSize}")
    List<Course> courasPage(Integer pageNum,Integer pageSize);
    // 模糊查询  根据教师名 课程号  课程名查询
//    按照课程名模糊
    @Select("SELECT course.*,teacher.name as teacherName FROM course,teacher WHERE teacher.job_id= course.job_id and  (course_name LIKE #{str} or teacher.`name` like #{str} ) ")
    List<Course> courasPage_like(String str);

    // 分类查询  根据课程类别
    @Select("SELECT * FROM course where (course_grade=#{grade} or course_grade is null  ) and course_class = #{choose} limit #{pageNum}, #{pageSize} ")
    List<Course> courasPage_class(Integer pageNum,Integer pageSize,Integer grade,String choose);

//    根据教师id 查询
    @Select("select  * from  course where job_id = #{teacher_id} and course_grade = #{grade}")
    List <Course> teacherCourse(Integer teacher_id ,Integer grade);
    @Select("select  * from  course where job_id = #{teacher_id} and course_id = #{course_id}")
    List <Course> teacherCourse_id(Integer teacher_id ,String course_id);

    @Select("select * from  course where course_id = #{id}")
    Course COURSE(Integer id);

    @Select("select * from course where job_id = #{job_id}")
    List<Course> TeacherCourse(Integer job_id);
    @Select("SELECT course_name,room_id,course_time FROM course,course_sort WHERE job_id = #{teacher_id} and course.course_id = course_sort.course_id")
    List<Course> ScheduleTeacher(Integer teacher_id);
    @Select("select course.course_name,course_sort.course_time,course_sort.room_id FROM course,course_sort,course_select WHERE course_select.student_id=#{student_id} and course_sort.course_id = course_select.course_id and course_sort.course_id =course.course_id")
    List<Course> ScheduleStudent(Integer student_id);

    @Update("update course set course_name = #{course_name},course_class=#{course_class},course_grade = #{course_grade},course_msg=#{course_msg} , job_id =#{job_id} where course_id = #{course_id}")
    Integer setCourseMsg(Course course);

    @Select("SELECT course.*,teacher.name as teacherName FROM course,teacher WHERE course_id = #{str} and teacher.job_id= course.job_id")
    List<Course> Course_idSelect(String str);

    @Select("select  * from  course where job_id = #{teacher_id} and course_name = #{str}")
    List<Course> CourseCourseName(Integer teacher_id, String str);

}

